<template>
  <div>
<!--    //。。。。。。。。。。。。-->
    <el-container style="height: 910px; border: 1px solid #eee">
      <el-aside width="220" style="background-color: rgb(44,44,44)">
        <el-menu router style="background-color: rgb(44,44,44);">
          <br>
          <span style="color: #fff5f5;font-size: 20px">
            <i class="el-icon-s-home"></i>
            农产品溯源平台
          </span>
          <br><br>
          <el-submenu v-for="m in menus" v-bind:key="m.id" :index="m.id">
            <template slot="title">
              <i class="el-icon-message"></i>
              <span style="color: #ffffff;font-size: 17px">{{m.name}}</span>
            </template>
            <el-menu-item-group style="background-color: rgb(44,44,44);">
              <el-menu-item style="color: #dae4e6;font-size: 15px" v-for="c in m.children" v-bind:key="c.id" :index="c.path">
                {{ c.name }}
              </el-menu-item>
            </el-menu-item-group>
          </el-submenu>
        </el-menu>
      </el-aside>
      <el-container>
        <el-header style="text-align: right; font-size: 20px">
          <span style="font-size: 18px">
            当前用户名字:{{loginName}}
          </span>
          <el-dropdown style="font-size: 20px">
            <i class="el-icon-loading" style="color: #00caca;margin: 15px"></i>
            <el-dropdown-menu slot="dropdown" style="color: #01a6ac">
              ---当前登录人数：{{online}}---
            </el-dropdown-menu>
          </el-dropdown>
          <i class="el-icon-switch-button" style="color: #ff0000;margin-right: 10px" @click="exit"></i>
        </el-header>
        <el-main>
          <router-view/>
        </el-main>
      </el-container>
    </el-container>
  </div>

</template>

<script>
export default {
  name: "IndexView",
  data() {
    return {
      menus:[],
      loginName:sessionStorage.getItem("loginName"),
      online:'',
      form:{}
    }
  }, methods: {
    getMenu(){
      this.axios.get("http://127.0.0.1:10010/menuservice/menu/list").then(res=>{
        this.menus=res.data.data;
      })
    },exit(){
      this.axios.get("http://localhost:10010/userservice/user/exit").then(res=>{
        if(res.data.code==200){
          this.$message.success(res.data.msg);
          sessionStorage.removeItem("token");
          this.$router.push("/");
        }else{
          this.$message.error(res.data.msg);
        }
      })
    },useronline(){
      this.axios.get("http://localhost:10010/userservice/user/online").then(res=>{
        this.online=res.data.data;
      })
    },
    out() {
      this.axios.post("http://localhost:10010/userservice/user/forceduser", this.form).then(res => {
        if (res.data.code == 200) {
          this.$message.success(res.data.msg);
        } else {
          this.$message.error(res.data.msg);
          this.$router.push("/")
        }
      })
    }
  }, created() {
    this.out()
    this.getMenu();
    this.useronline();
    //超过时间强制退出
    this.axios.post("http://localhost:10010/userservice/user/forced").then(res=>{
      if(res.data.code==200){
        this.$message.success("当前登录已失效");
        sessionStorage.removeItem("token");
        this.$router.push("/");
      }
    })
  },

}
</script>

<style scoped>
/deep/ .el-menu-item:hover {
  background-color: indianred;
}
</style>

